package com.joysuch.wwyt.attendant.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.joysuch.wwyt.attendant.bean.AttendantAreaBean;
import com.joysuch.wwyt.attendant.bean.AttendantAreaReqBean;
import com.joysuch.wwyt.attendant.service.AttendantAreaService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.exception.ApiBusinessException;
import com.joysuch.wwyt.core.exception.ApiCoreException;
import com.joysuch.wwyt.workflow.bean.CardLineBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * @author xsx
 * @version 1.0
 * @date 2023/2/15 17:46
 */
@RestController
@RequestMapping("/attendant/area")
@Api(tags = "跟班区域")
@Slf4j
public class AttendantAreaController {

    @Autowired
    private AttendantAreaService attendantAreaService;

    @PostMapping("save")
    @ApiOperation("保存跟班区域")
//    @RequiresPermissions("attendant:area:save")
    public ResultBean save(@RequestBody AttendantAreaBean bean) throws ParseException {
        attendantAreaService.saveEntity(bean);
        return ResultBean.defaultSuccessResult();
    }

    @PostMapping("update")
    @ApiOperation("修改跟班区域")
    public ResultBean update(@RequestBody AttendantAreaBean bean) throws ApiCoreException {
        attendantAreaService.updateEntity(bean);
        return ResultBean.defaultSuccessResult();
    }


    @PostMapping("batchSave")
    @ApiOperation("批量保存跟班区域")
    public ResultBean batchSave(@RequestBody List<AttendantAreaBean> beans) throws ParseException {
        attendantAreaService.saveEntitys(beans);
        return ResultBean.defaultSuccessResult();
    }

    @GetMapping("findById")
    @ApiOperation("查看跟班区域详情")
    public ResultBean findById(@RequestParam(value = "id") Long id) {
        return ResultBean.success(attendantAreaService.findById(id));
    }

    @GetMapping("selectPage")
    @ApiOperation("查询跟班区域列表")
    public ResultBean selectPage(AttendantAreaReqBean bean){
        Page<AttendantAreaBean> page = attendantAreaService.selectPage(bean);
        return ResultBean.pageData(page.getRecords(),page.getTotal());
    }

    @PostMapping("delete")
    @ApiOperation("删除跟班区域")
    public ResultBean delete(Long id) throws ApiCoreException {
        attendantAreaService.deleteEntity(id);
        return ResultBean.defaultSuccessResult();
    }


    @GetMapping("list")
    @ApiOperation("查询跟班区域列表")
    public ResultBean list(String name){
        List<CardLineBean> list = attendantAreaService.selectList(name);
        return ResultBean.success(list);
    }

    @PostMapping("syncArea")
    @ApiOperation("同步跟班区域")
    public ResultBean syncArea(Long id) throws ApiCoreException {
        return attendantAreaService.syncArea(id);
    }

}
